/****** Object:  Stored Procedure dbo.[SavePDFDocumentBlob]  ******/    
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SavePDFDocumentBlob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SavePDFDocumentBlob]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO   
/************************************************************************************************    
* Name:  SavePDFDocumentBlob    
* Purpose: Stored procedure to Save the converetd documentblob    
    
* PARAMETERS      
* Name        Description    
* -------------------------    -----------------------------    
* @documentId       documentId, whose blob was converted    
* @blob			    Converter PDFBlob
* @status			conversion Status(1 or 0 --> representing success or failure)
************************************************************************************************/    
CREATE PROCEDURE dbo.[SavePDFDocumentBlob]    
(    
 @documentid int,    
 @blob  image = null,    
 @status bit    
)      
AS      
BEGIN      
 SET NOCOUNT ON      
  if exists (Select 1 from ConvertedPDFDocument where documentId = @documentid)    
	 BEGIN    
	  UPDATE ConvertedPDFDocument     
		 SET PDFBlob = @blob,    
		  DateModified = GetDate(),    
		  Status = @status    
		 WHERE DocumentId = @documentId          
	 END    
  ELSE    
	 BEGIN    
	  INSERT INTO ConvertedPDFDocument    
		 (DocumentId ,PDFBlob, Status, DateCreated)    
		VALUES    
		 (@documentId,@blob,@status,GetDate())    
	 END      
 SET NOCOUNT OFF      
END 


